#include "Particle.h"


Particle::Particle(Emitter * MyEmitter)
{
	ParentEmitter = MyEmitter;
	Renew();
}


Particle::~Particle(void)
{
	ParentEmitter = nullptr;
}

void Particle::Update(float fElapsedTime)
{
		m_fCurrentLife -= fElapsedTime;
		//float change = m_fLife - m_fCurrentLife * 100;
		m_nColorA +=  (int)(((ParentEmitter->m_nEndAlpha - ParentEmitter->m_nStartAlpha) )* fElapsedTime);
		m_nColorR +=  (int)(((ParentEmitter->m_nEndR - ParentEmitter->m_nStartR))* fElapsedTime);
		m_nColorG += (int)(((ParentEmitter->m_nEndG - ParentEmitter->m_nStartG) )* fElapsedTime);
		m_nColorB += (int)(((ParentEmitter->m_nEndB - ParentEmitter->m_nStartB)  )* fElapsedTime);
		m_fVelX +=  ((ParentEmitter->m_fEndVelX - ParentEmitter->m_fStartVelX) / m_fCurrentLife) * fElapsedTime;
		m_fVelY +=  ((ParentEmitter->m_fEndVelY - ParentEmitter->m_fStartVelY) / m_fCurrentLife) * fElapsedTime;
		m_fPosX = m_fPosX + (m_fVelX * fElapsedTime);
		m_fPosY = m_fPosY + (m_fVelY * fElapsedTime);
		m_fRotation += ((ParentEmitter->m_fEndRotation - ParentEmitter->m_fStartRotation) / m_fCurrentLife) * fElapsedTime;
		m_fScale += ((ParentEmitter->m_fEndScale - ParentEmitter->m_fStartScale) / m_fCurrentLife) * fElapsedTime;

}

void Particle::Renew()
{
	m_nColorA = ParentEmitter->m_nStartAlpha;
	m_nColorR = ParentEmitter->m_nStartR;
	m_nColorG = ParentEmitter->m_nStartG;
	m_nColorB = ParentEmitter->m_nStartB;
	m_fPosX = (float)(rand() % (int)ParentEmitter->m_fPosX + 1);
	m_fPosY = (float)(rand() % (int)ParentEmitter->m_fPosY +1);

	m_fLife = (float)(rand() % (int) ParentEmitter->m_fCurrLife + 1);
	m_fCurrentLife = m_fLife;
	m_fRotation = ParentEmitter->m_fStartRotation;
	m_fScale = ParentEmitter->m_fStartScale;
	m_fVelX = ParentEmitter->m_fStartVelX;
	m_fVelY = ParentEmitter->m_fStartVelY;
}